/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import jsbn from './jsbn'
// const jsbn = require('./jsbn') 

var BigInteger = jsbn.BigInteger;
const BASE_COUNT = 100;
const LONG_COUNT = 1000;
const MAX_COUNT  = 100000;

/* returns index of lowest 1-bit (or -1 if none) */
function getLowestSetBit_Test() {    
    var bi = new BigInteger('1024');
    let result
    let startTime = Date.now()
    for (let i=0;i<MAX_COUNT;i++) {
        result = bi.getLowestSetBit()
    } 
    let endTime = Date.now() 
    let time = endTime - startTime
    print("jsbn_getLowestSetBit: " + time +" ms")   
    areEqual(10, result) 

    // print(result)
}
 
/* Expected results and actual results verification  */
function areEqual(expected, actual) {
    // If expected and actual are both NaN, consider them equal.
    if (expected === actual || expected !== expected && actual !== actual) {
        // print('Success')
    } else {
        let error = 
        '  Failed areEqual test' +
        '  Expected: ' + expected +
        '  Actual:   ' + actual
        ;
        throw(error) 
    }
}

// function print(s){
//     console.log(s)
// }

/*  Benchmark  */
function jsbnRun() { 
    getLowestSetBit_Test()
} 
jsbnRun()